<?php
$str=curl('http://www.chinanews.com/ ');
//echo $str;
$preg='# <!---->.*<!--tupian-->#isU';
preg_match($preg,$str,$arr);
$pregll='#<li>.*<div class=".*">.*<a href="(.*)"><img src="(.*)"></a>.*</div>.*<div class="righttext">.*<p><a style="display:block;line-height: 23px;" class="gray6" href=".*">(.*)</a></p>.*</div>.*<div class="clear"></div>.*</li>#isU';
preg_match_all($pregll,$arr[0],$arr_gg);
//print_r($arr_gg);die;
foreach($arr_gg[1] as $k=>$value)
{
    $arr_mm['url']=$arr_gg[1][$k];
    $arr_mm['img_url']=$arr_gg[2][$k];
    $arr_mm['title']=$arr_gg[3][$k];
    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    $sql="insert into yuekao(url,img_url,title) VALUES('{$arr_mm['url']}','{$arr_mm['img_url']}','{$arr_mm['title']}')";
    $dbh->exec($sql);
}
function curl($url)
{
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
    $str=curl_exec($ch);
    return $str;
}

